var t = require("../../../utils/cityList.js"), i = getApp();

Page({
    data: {
        provinceArray: [],
        cityArray: [],
        pricesArray: [],
        selectArray: [],
        province: "",
        isSelectProvince: !0
    },
    clickProvince: function(i) {
        var a = i.currentTarget.dataset.index, e = i.currentTarget.dataset.name;
        if (this.data.province = e, "北京市" == e || "天津市" == e || "上海市" == e || "重庆市" == e) this.addCityToSelect(e); else {
            e = t.cityList.provinces[a];
            this.setData({
                cityArray: e.citys,
                isSelectProvince: !1
            });
        }
    },
    clickCity: function(t) {
        var i = t.currentTarget.dataset.city;
        this.addCityToSelect(i);
    },
    addCityToSelect: function(t) {
        var i = !1, a = this.data.pricesArray, e = !0, r = !1, c = void 0;
        try {
            for (var n, o = a[Symbol.iterator](); !(e = (n = o.next()).done); e = !0) if (n.value.city == t) {
                i = !0;
                break;
            }
        } catch (t) {
            t = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(t);
            r = !0, c = t;
        } finally {
            try {
                !e && o.return && o.return();
            } finally {
                if (r) throw c;
            }
        }
        0 == i && (a = a.concat({
            city: t,
            province: this.data.province
        }));
        var s = a.map(function(t, i, a) {
            return t.city;
        });
        this.setData({
            selectArray: s,
            pricesArray: a
        });
    },
    clickBackProvince: function(t) {
        this.setData({
            isSelectProvince: !0
        });
    },
    clickDel: function(t) {
        var i = t.currentTarget.dataset.index, a = this.data.pricesArray;
        a.splice(i, 1);
        var e = a.map(function(t, i, a) {
            return t.city;
        });
        this.setData({
            selectArray: e,
            pricesArray: a
        });
    },
    clickConfirm: function(t) {
        var i = JSON.stringify(this.data.pricesArray);
        wx.navigateTo({
            url: "/pages/sendOrder/editCityPrice/editCityPrice?data=" + i
        });
    },
    getCityPriceData: function() {
        var t = this;
        i.network.post({
            url: i.url.GetWeddingOrderUserPriceList,
            params: {},
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(a) {
                if (1 == a.data.result) {
                    var e = a.data.data.cityPrices.map(function(t, i, a) {
                        return t.city;
                    });
                    t.setData({
                        pricesArray: a.data.data.cityPrices,
                        selectArray: e
                    });
                } else i.util.showToast(a.data.message);
            },
            fail: function() {
                i.util.showToast("获取城市价格失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading();
            }
        });
    },
    onLoad: function(i) {
        this.getCityPriceData();
        var a = t.cityList.provinces.map(function(t, i, a) {
            return t.name;
        });
        this.setData({
            provinceArray: a
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});